fix(explore): search file content instead of filename for similar code#21
Merged
fix(explore): search file content instead of filename for similar code#21
Conversation
Bug: explore similar searched filename as text → 0 results Fix: Read file content and search its embeddings Changes: - Extract file utilities (resolveFilePath, readFileContent, etc.) - Add 22 unit tests for utilities (100% coverage) - Refactor explore similar to use utilities - Add --threshold option (default: 0.5) - Improve error messages for missing/empty files Before: $ dev explore similar file.ts ⚠ No similar code found # searched "file.ts" as text After: $ dev explore similar packages/core/src/vector/store.ts 1. packages/core/src/vector/README.md (64.1% similar) 2. packages/core/src/vector/embedder.ts (61.7% similar) Tests: 22/22 passing ✅
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Bug
explore similarwas searching the filename as text instead of reading and searching the file's content embeddings.$ dev explore similar coordinator.ts ⚠ No similar code found # Searched "coordinator.ts" as text ❌✅ Fix
Read file content and search its embeddings for semantic similarity.
📝 Changes
1. Extracted File Utilities (
cli/src/utils/file.ts)Pure, testable functions:
resolveFilePath: Resolve paths relative to repo rootnormalizeFilePath: Create relative pathsreadFileContent: Read and validate file contentprepareFileForSearch: Prepare file for similarity search2. 100% Test Coverage (
cli/src/utils/file.test.ts)22 unit tests covering:
3. Refactored
explore similar--thresholdoption (default: 0.5)🧪 Verification
Before:
After:
Tests:
$ pnpm test packages/cli/src/utils/file.test.ts ✓ 22 tests passing ✅📊 Stats
🚀 Impact
Users can now find semantically similar code based on actual file content, not filenames. Feature works as intended!